main = function() {
	this._endringerAJAX = new AJAXPeriodic("EndringerHent");
	this._sletteAJAX = new AJAXForbindelse("MedlemSlett");
	this._nyEditAJAX = new AJAXForbindelse("MedlemData");
	this._GUIHandler = new GUIHandler();
};
	
main.prototype.init = function() {
	var thisObj = this;
	thisObj._endringerAJAX.setSuccessHandler(function(httprequest) {
		try {
			var jsontekst = httprequest.responseText;
			var objekt = JSON.parse(jsontekst);
			if (objekt.status && objekt.loggId > thisObj._endringerAJAX.getLastLog()) {
				thisObj._GUIHandler.updateTable(objekt);
			}
			thisObj._endringerAJAX.setInterval(10000);
			thisObj._endringerAJAX.setLastLog(objekt.loggId);
			thisObj._endringerAJAX.start();
		} catch (e) {
			window.alert(e);
		}
	});
	this._nyEditAJAX.setSuccessHandler(function() {
		thisObj._GUIHandler.restoreNewMemberButton();
		thisObj._restartAutoUpdate();
	});
	this._sletteAJAX.setSuccessHandler(function() {
		thisObj._restartAutoUpdate();
	});
	this._GUIHandler.restoreNewMemberButton();
	this._endringerAJAX.start();
};
main.prototype._restartAutoUpdate = function() {
	this._endringerAJAX.stopp();
	this._endringerAJAX.setInterval(0);
	this._endringerAJAX.start();
};
main.prototype._getRowIdForButton = function(e) {
	if (typeof e.target == "undefined") {
		e.target = e.srcElement;
	}
	return e.target.parentNode.parentNode.id;
};
main.prototype.deleteMember = function(e) {
	this._sletteAJAX.post("medlemId="+this._getRowIdForButton(e));
};
main.prototype.editMember = function(e) {
	var id = this._getRowIdForButton(e);
	this._GUIHandler.showMemberEdit(id);
};
main.prototype.newMember = function() {
	this._GUIHandler.showMemberEdit();
};
main.prototype.saveMember = function() {
	this._nyEditAJAX.post("medlemId="+$("#idInput").val()+"&fornavn="+$("#fNavnInput").val()+
			"&etternavn="+$("#eNavnInput").val()+"&adresse="+$("#adresseInput").val()+
			"&telefon="+$("#tlfInput").val());
};